package cn.njupt.unionfind;

public class Quick_Find extends Union_Find {

    public Quick_Find(int capacity){
        super(capacity);
        if(capacity<=0){
            throw new IllegalArgumentException("参数传递不正确");
        }
    }

    public void union(int i,int j){
        int iParent=find(i);
        int jParent=find(j);
        if(iParent==jParent)return;
        for (int k = 0; k < parent.length; k++) {
            if(parent[k]==iParent){
                parent[k]=jParent;
            }
        }
    }

    public int find(int i){
        rangCheck(i);
        return parent[i];

    }




}
